#include "led_app.h"

void LedTask(void)
{
    static uint32_t breathCounter = 0;
    static uint8_t pwmCounter = 0;
    static const uint16_t breathPeriod = 4000;
    static const uint8_t pwmMax = 10;
    static const float phaseShift = 3.14159f / 3.0f;

    breathCounter = (breathCounter + 1) % breathPeriod;

    pwmCounter = (pwmCounter + 1) % pwmMax;

    for(uint8_t i = 0; i < 6; i++)
    {
        float angle = (2.0f * 3.14159f * breathCounter) / breathPeriod - i * phaseShift;
        float sinValue = sinf(angle);
        float enhancedValue = sinValue > 0 ? powf(sinValue, 0.5f) : -powf(-sinValue, 0.5f);

        enhancedValue = enhancedValue > 0.7f || enhancedValue < -0.7f ? enhancedValue : enhancedValue * 0.6f;

        uint8_t brightness = (uint8_t)((enhancedValue + 1.0f) * pwmMax / 2.0f);

        ucLed[i] = (pwmCounter < brightness) ? 1 : 0;
    }

    LedDisp(ucLed);
}
